package org.ziwei.paipan;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.ziwei.paipan.biao.GanXiZhuXingBiao;
import org.ziwei.paipan.biao.GongGanBiao;
import org.ziwei.paipan.biao.MiaoXianBiao;
import org.ziwei.paipan.biao.MingShenGongBiao;
import org.ziwei.paipan.biao.RiXiZhuXingBiao;
import org.ziwei.paipan.biao.ShiXiZhuXingBiao;
import org.ziwei.paipan.biao.TianFuXingBiao;
import org.ziwei.paipan.biao.Utils;
import org.ziwei.paipan.biao.WuXingJuBiao;
import org.ziwei.paipan.biao.YueXiZhuXingBiao;
import org.ziwei.paipan.biao.ZaXingBiao;
import org.ziwei.paipan.biao.ZhiXiZhuXingBiao;
import org.ziwei.paipan.biao.ZiWeiXingBiao;
import org.ziwei.paipan.var.BoShiShen;
import org.ziwei.paipan.var.ChangShengShen;
import org.ziwei.paipan.var.DiZhi;
import org.ziwei.paipan.var.JiangQianShen;
import org.ziwei.paipan.var.MiaoXian;
import org.ziwei.paipan.var.Sex;
import org.ziwei.paipan.var.ShiErGong;
import org.ziwei.paipan.var.StarCode;
import org.ziwei.paipan.var.TaiSuiShen;
import org.ziwei.paipan.var.TianGan;
import org.ziwei.paipan.var.WuXing;
import org.ziwei.paipan.var.YinYang;

/**
 * 命盘
 * http://www.freehoro.net/ZWDS/Tutorial/PaiPan/index.php
 */
public class MingPan {

	private BasicInfo basicInfo; 		//基本信息
	
	private DiZhi mingGong;      //命宫所在地支

	private DiZhi shenGong;      //身宫所在地支
	
	private List<Gong> gongList = new ArrayList<Gong>();   //十二宫列表，从子到癸依次入列表
	
	private Integer curYear = 0;
	
	private Map<StarCode, Star> starMap = new HashMap<StarCode, Star>();    //星曜表

	public MingPan(Date birthday, Sex sex, int curYear){
		init(birthday, sex, curYear);
	}

	/**
	 * @param birthday
	 * @param sex
	 * @param curYear
	 */
	private void init(Date birthday, Sex sex, int curYear){
		this.curYear = curYear;
		this.basicInfo = new BasicInfo(birthday, sex, curYear);
		
		//安命宫
		mingGong = MingShenGongBiao.anMingGong(basicInfo.getMonth(), basicInfo.getShiChen());
		setShenGong(MingShenGongBiao.anShenGong(basicInfo.getMonth(), basicInfo.getShiChen()));
		int mingGongIndex = mingGong.ordinal();
		
		for(DiZhi dz : DiZhi.values()){
			Gong gong = new Gong();
			//安十二宫地支，从子到癸
			gong.setGongZhi(dz);
			//安十二宫天干
			gong.setGongGan(GongGanBiao.anGongGan(this.basicInfo.getTianGan(), dz));
			//安十二宫
			gong.setShiErGong(ShiErGong.values()[(12-dz.ordinal()+mingGongIndex)%12]);
			gongList.add(gong);
		}
		
		//定五行局
		basicInfo.setWuXing(WuXingJuBiao.dingWuXingJu(gongList.get(mingGongIndex).getGongGan(), gongList.get(mingGongIndex).getGongZhi()));
		
		//安十四正星
		anShiSiZhengYao();

		//安干系诸星
		anGanXiZhuXing();
		
		//安支系诸星
		anZhiXiZhuXing();
		
		//安月系诸星
		anYueXiZhuXing();
		
		//安日系诸星
		anRiXiZhuXing();
		
		//安时系诸星
		anShiXiZhuXing();
		
		//安杂曜
		anZaXing();
		
		//安四化星
		anSiHuaXing();
		/**
		 * 安长生十二神
		 * 长生落宫由五行局确定：金长生在已，木长生在亥，火长生在寅，水土长生在申，由长生宫起头，男逆女顺，依次安长生、沐浴、冠带、临官、帝旺、衰、病、死、墓、绝、胎、养，一官安一星。 例如五行局属土五局，长生宫在申，依次排列长生、沐浴。
		 */
		int changSheng = 0;
		WuXing wuXing = basicInfo.getWuXing();
		switch ( wuXing ){
		case JIN:
			changSheng = 5;
			break;
		case MU:
			changSheng = 11;
			break;
		case HUO:
			changSheng = 2;
			break;
		default:
			changSheng = 8;
		}
		for(ChangShengShen css : ChangShengShen.values()){
			int index = 0;
			if(basicInfo.getSex() == Sex.M){
				index = (changSheng - css.ordinal() + 12) % 12;
			}else{
				index = (changSheng + css.ordinal()) % 12;
			}
			gongList.get(index).setChangShengShen(css);
		}
		
		/**
		 * 安博士十二神
		 * 由命盘上的禄存星所在宫打头，阳男阴女顺行，阳女阴男逆行，依次布下博士、力士、青龙、小耗、将军、奏书、飞廉、喜神、病符、大耗、伏兵、官符、每宫安一星
		 */
		DiZhi luCunDiZhi = GanXiZhuXingBiao.anLuCun(basicInfo.getTianGan());
		for(BoShiShen bss : BoShiShen.values()){
			int index = 0;
			if((basicInfo.getSex() == Sex.M && basicInfo.getYinYang() == YinYang.YANG) ||(basicInfo.getSex() == Sex.F && basicInfo.getYinYang() == YinYang.YIN)){
				index = (bss.ordinal() + luCunDiZhi.ordinal()) % 12;
			}else{
				index = (12 + luCunDiZhi.ordinal() - bss.ordinal()) % 12;
			}
			gongList.get(index).setBoShiShen(bss);
		}
		
		/**
		 * 安太岁十二神
		 * 以出生年地支安太岁星，顺时针安十二宫
		 * 例如辰年生人，辰宫安太岁，顺行每宫一星，巳宫安太阳，午宫安丧门...
		 */
		for(TaiSuiShen tss : TaiSuiShen.values()){
			int index = (tss.ordinal() + basicInfo.getDiZhi().ordinal()) % 12;
			gongList.get(index).setTaiSuiShen(tss);
		}
		
		/**
		 * 安将前十二神
		 * 根据流年年支的三合宫的旺地，得到将星起何宫，顺时针按攀安，岁驿，息申……顺序置于个宫。例如丑年生人，三合宫位巳酉丑，旺地为酉，将星起酉宫，依次排列各宫。
		 */
		int jiangXing = -1;
		int temp = basicInfo.getDiZhi().ordinal() % 4;
		if(temp == 0 ) jiangXing = 0;
		else if(temp == 1) jiangXing = 9;
		else if(temp == 2) jiangXing = 6;
		else if(temp == 3) jiangXing = 3;
		for(JiangQianShen jqs : JiangQianShen.values()){
			int index = (jqs.ordinal() + jiangXing) % 12;
			gongList.get(index).setJiangQianShen(jqs);
		}
		
		
		//定庙旺失陷
		dingMiaoXian();
		
		//定大限
		dingDaXian();
		
		//安大运诸星
		anDaYunZhuXing();
		
		//定小限, 安流年诸星
		anLiuNianZhuXing();
		
		//安斗君，安流月诸星
		anLiuYueZhuXing();
		
	}
	
	private void anShiSiZhengYao(){
		//安紫微星
		DiZhi ziWeiDiZhi = ZiWeiXingBiao.anZiWeiXing(basicInfo.getDay(), basicInfo.getWuXing().getNum());
		Star ziWeiStar = new Star(StarCode.ZIWEI, StarCode.ZIWEI.getName());
		ziWeiStar.setGongZhi(ziWeiDiZhi);
		starMap.put(StarCode.ZIWEI, ziWeiStar);
		gongList.get(ziWeiDiZhi.ordinal()).getZhengYaoList().add(ziWeiStar);
		
		//安天机
		DiZhi tianJiDiZhi = ZiWeiXingBiao.anTianJiXing(ziWeiDiZhi);
		Star tianJiStar = new Star(StarCode.TIANJI, StarCode.TIANJI.getName());
		tianJiStar.setGongZhi(tianJiDiZhi);
		starMap.put(StarCode.TIANJI, tianJiStar);
		gongList.get(tianJiDiZhi.ordinal()).getZhengYaoList().add(tianJiStar);
		
		//安太阳
		DiZhi taiYangDiZhi = ZiWeiXingBiao.anTaiYangXing(ziWeiDiZhi);
		Star taiYangStar = new Star(StarCode.TAIYANG, StarCode.TAIYANG.getName());
		taiYangStar.setGongZhi(taiYangDiZhi);
		starMap.put(StarCode.TAIYANG, taiYangStar);
		gongList.get(taiYangDiZhi.ordinal()).getZhengYaoList().add(taiYangStar);
	
		//安武曲
		DiZhi wuQuDiZhi = ZiWeiXingBiao.anWuQuXing(ziWeiDiZhi);
		Star wuQuStar = new Star(StarCode.WUQU, StarCode.WUQU.getName());
		wuQuStar.setGongZhi(wuQuDiZhi);
		starMap.put(StarCode.WUQU, wuQuStar);
		gongList.get(wuQuDiZhi.ordinal()).getZhengYaoList().add(wuQuStar);
		
		//安天同
		DiZhi tianTongDiZhi = ZiWeiXingBiao.anTianTongXing(ziWeiDiZhi);
		Star tianTongStar = new Star(StarCode.TIANTONG, StarCode.TIANTONG.getName());
		tianTongStar.setGongZhi(tianTongDiZhi);
		starMap.put(StarCode.TIANTONG, tianTongStar);
		gongList.get(tianTongDiZhi.ordinal()).getZhengYaoList().add(tianTongStar);
		
		//安廉贞
		DiZhi lianZhenDiZhi = ZiWeiXingBiao.anLianZhenXing(ziWeiDiZhi);
		Star lianZhenStar = new Star(StarCode.LIANZHEN, StarCode.LIANZHEN.getName());
		lianZhenStar.setGongZhi(lianZhenDiZhi);
		starMap.put(StarCode.LIANZHEN, lianZhenStar);
		gongList.get(lianZhenDiZhi.ordinal()).getZhengYaoList().add(lianZhenStar);
	
		//安天府
		DiZhi tianFuDiZhi = TianFuXingBiao.anTianFuXing(ziWeiDiZhi);
		Star tianFuStar = new Star(StarCode.TIANFU, StarCode.TIANFU.getName());
		tianFuStar.setGongZhi(tianFuDiZhi);
		starMap.put(StarCode.TIANFU, tianFuStar);
		gongList.get(tianFuDiZhi.ordinal()).getZhengYaoList().add(tianFuStar);
		
		//安太阴
		DiZhi taiYinDiZhi = TianFuXingBiao.anTaiYinXing(tianFuDiZhi);
		Star taiYinStar = new Star(StarCode.TAIYIN, StarCode.TAIYIN.getName()); 
		taiYinStar.setGongZhi(taiYinDiZhi);
		starMap.put(StarCode.TAIYIN, taiYinStar);
		gongList.get(taiYinDiZhi.ordinal()).getZhengYaoList().add(taiYinStar);
	
		//安贪狼
		DiZhi tanLangDiZhi = TianFuXingBiao.anTanLangXing(tianFuDiZhi);
		Star tangLangStar = new Star(StarCode.TANLANG, StarCode.TANLANG.getName());
		tangLangStar.setGongZhi(tanLangDiZhi);
		starMap.put(StarCode.TANLANG, tangLangStar);
		gongList.get(tanLangDiZhi.ordinal()).getZhengYaoList().add(tangLangStar);

		//安巨门
		DiZhi juMenDiZhi = TianFuXingBiao.anJuMenXing(tianFuDiZhi);
		Star juMenStar = new Star(StarCode.JUMEN, StarCode.JUMEN.getName());
		juMenStar.setGongZhi(juMenDiZhi);
		starMap.put(StarCode.JUMEN, juMenStar);
		gongList.get(juMenDiZhi.ordinal()).getZhengYaoList().add(juMenStar);
		
		//安天相
		DiZhi tianXiangDiZhi = TianFuXingBiao.anTianXiangXing(tianFuDiZhi);
		Star tianXiangStar = new Star(StarCode.TIANXIANG, StarCode.TIANXIANG.getName()); 
		tianXiangStar.setGongZhi(tianXiangDiZhi);
		starMap.put(StarCode.TIANXIANG, tianXiangStar);
		gongList.get(tianXiangDiZhi.ordinal()).getZhengYaoList().add(tianXiangStar);
		
		//安天梁
		DiZhi tianLiangDiZhi = TianFuXingBiao.anTianLiangXing(tianFuDiZhi);
		Star tianLiangStar = new Star(StarCode.TIANLIANG, StarCode.TIANLIANG.getName()); 
		tianLiangStar.setGongZhi(tianLiangDiZhi);
		starMap.put(StarCode.TIANLIANG, tianLiangStar);
		gongList.get(tianLiangDiZhi.ordinal()).getZhengYaoList().add(tianLiangStar);
	
		//安七杀
		DiZhi qiShaDiZhi = TianFuXingBiao.anQiShaXing(tianFuDiZhi);
		Star qiShaStar = new Star(StarCode.QISHA, StarCode.QISHA.getName()); 
		qiShaStar.setGongZhi(qiShaDiZhi);
		starMap.put(StarCode.QISHA, qiShaStar);
		gongList.get(qiShaDiZhi.ordinal()).getZhengYaoList().add(qiShaStar);
	
		//安破军
		DiZhi poJunDiZhi = TianFuXingBiao.anPoJunXing(tianFuDiZhi);
		Star poJunStar = new Star(StarCode.POJUN, StarCode.POJUN.getName()); 
		poJunStar.setGongZhi(poJunDiZhi);
		starMap.put(StarCode.POJUN, poJunStar);
		gongList.get(poJunDiZhi.ordinal()).getZhengYaoList().add(poJunStar);
	}
	
	private void anGanXiZhuXing(){
		//安天魁
		DiZhi tianKuiDiZhi = GanXiZhuXingBiao.anTianKui(basicInfo.getTianGan());
		Star tianKuiStar =  new Star(StarCode.TIANKUI, StarCode.TIANKUI.getName());
		tianKuiStar.setGongZhi(tianKuiDiZhi);
		starMap.put(StarCode.TIANKUI, tianKuiStar);
		gongList.get(tianKuiDiZhi.ordinal()).getFuYaoList().add(tianKuiStar);
		
		//安天钺
		DiZhi tianYueDiZhi = GanXiZhuXingBiao.anTianYue(basicInfo.getTianGan());
		Star tianYueStar =  new Star(StarCode.TIANYUE, StarCode.TIANYUE.getName());
		tianYueStar.setGongZhi(tianYueDiZhi);
		starMap.put(StarCode.TIANYUE, tianYueStar);
		gongList.get(tianYueDiZhi.ordinal()).getFuYaoList().add(tianYueStar);
		
		//安禄存
		DiZhi luCunDiZhi = GanXiZhuXingBiao.anLuCun(basicInfo.getTianGan());
		Star luCunStar = new Star(StarCode.LUCUN, StarCode.LUCUN.getName()); 
		luCunStar.setGongZhi(luCunDiZhi);
		starMap.put(StarCode.LUCUN, luCunStar);
		gongList.get(luCunDiZhi.ordinal()).getFuYaoList().add(luCunStar);
		
		//安擎羊
		DiZhi qingYangDiZhi = GanXiZhuXingBiao.anQingYang(basicInfo.getTianGan());
		Star qingYangStar = new Star(StarCode.QINGYANG, StarCode.QINGYANG.getName());
		qingYangStar.setGongZhi(qingYangDiZhi);
		starMap.put(StarCode.QINGYANG, qingYangStar);
		gongList.get(qingYangDiZhi.ordinal()).getFuYaoList().add(qingYangStar);
		
		//安陀罗
		DiZhi tuoLuoDiZhi = GanXiZhuXingBiao.anTuoLuo(basicInfo.getTianGan());
		Star tuoLuoStar =  new Star(StarCode.TUOLUO, StarCode.TUOLUO.getName());
		tuoLuoStar.setGongZhi(tuoLuoDiZhi);
		starMap.put(StarCode.TUOLUO, tuoLuoStar);
		gongList.get(tuoLuoDiZhi.ordinal()).getFuYaoList().add(tuoLuoStar);
		
		//安天官
		DiZhi tianGuanDiZhi = GanXiZhuXingBiao.anTianGuan(basicInfo.getTianGan());
		Star tianGuanStar = new Star(StarCode.TIANGUAN, StarCode.TIANGUAN.getName()); 
		tianGuanStar.setGongZhi(tianGuanDiZhi);
		starMap.put(StarCode.TIANGUAN, tianGuanStar);
		gongList.get(tianGuanDiZhi.ordinal()).getZaYaoList().add(tianGuanStar);
		
		//安天福
		DiZhi tianFuDiZhi = GanXiZhuXingBiao.anTianFu(basicInfo.getTianGan());
		Star tianFuStar = new Star(StarCode.TIANFU1, StarCode.TIANFU1.getName());
		tianFuStar.setGongZhi(tianFuDiZhi);
		starMap.put(StarCode.TIANFU1, tianFuStar);
		gongList.get(tianFuDiZhi.ordinal()).getZaYaoList().add(tianFuStar);
		
		//安正空傍空
		DiZhi jieKong1DiZhi = GanXiZhuXingBiao.anJieKong1(basicInfo.getTianGan());
		DiZhi jieKong2DiZhi = GanXiZhuXingBiao.anJieKong2(basicInfo.getTianGan());
		
		Star zhengKongStar = new Star(StarCode.ZHENGJIEKONG, StarCode.ZHENGJIEKONG.getName());
		Star bangKongStar = new Star(StarCode.BANGJIEKONG, StarCode.BANGJIEKONG.getName());
		
		if(basicInfo.getTianGan().ordinal() % 2 == 0){
			//天干为阳
			zhengKongStar.setGongZhi(jieKong1DiZhi);
			bangKongStar.setGongZhi(jieKong2DiZhi);
		}else{
			zhengKongStar.setGongZhi(jieKong2DiZhi);
			bangKongStar.setGongZhi(jieKong1DiZhi);
		}
		starMap.put(StarCode.ZHENGJIEKONG, zhengKongStar);
		gongList.get(zhengKongStar.getGongZhi().ordinal()).getZaYaoList().add(zhengKongStar);
		starMap.put(StarCode.BANGJIEKONG, bangKongStar);
		gongList.get(bangKongStar.getGongZhi().ordinal()).getZaYaoList().add(bangKongStar);
		
		//安天厨
		DiZhi tianChuDiZhi = GanXiZhuXingBiao.anTianChu(basicInfo.getTianGan());
		Star tianChuStar = new Star(StarCode.TIANCHU, StarCode.TIANCHU.getName());
		tianChuStar.setGongZhi(tianChuDiZhi);
		starMap.put(StarCode.TIANCHU, tianChuStar);
		gongList.get(tianChuDiZhi.ordinal()).getZaYaoList().add(tianChuStar);
	}

	private void anZhiXiZhuXing(){

		//安红鸾
		DiZhi hongLuanDiZhi = ZhiXiZhuXingBiao.anHongLuan(basicInfo.getDiZhi());
		Star hongLuanStar = new Star(StarCode.HONGLUAN, StarCode.HONGLUAN.getName()); 
		hongLuanStar.setGongZhi(hongLuanDiZhi);
		starMap.put(StarCode.HONGLUAN, hongLuanStar);
		gongList.get(hongLuanDiZhi.ordinal()).getZaYaoList().add(hongLuanStar);
		
		//安天喜
		DiZhi tianXiDiZhi = ZhiXiZhuXingBiao.anTianXi(basicInfo.getDiZhi());
		Star tianXiStar = new Star(StarCode.TIANXI, StarCode.TIANXI.getName());
		tianXiStar.setGongZhi(tianXiDiZhi);
		starMap.put(StarCode.TIANXI, tianXiStar);
		gongList.get(tianXiDiZhi.ordinal()).getZaYaoList().add(tianXiStar);

		//安龙池
		DiZhi longChiDiZhi = ZhiXiZhuXingBiao.anLongChi(basicInfo.getDiZhi());
		Star longChiStar = new Star(StarCode.LONGCHI, StarCode.LONGCHI.getName());
		longChiStar.setGongZhi(longChiDiZhi);
		starMap.put(StarCode.LONGCHI, longChiStar);
		gongList.get(longChiDiZhi.ordinal()).getZaYaoList().add(longChiStar);

		//安凤阁
		DiZhi fengGeDiZhi = ZhiXiZhuXingBiao.anFengGe(basicInfo.getDiZhi());
		Star fengGeStar = new Star(StarCode.FENGGE, StarCode.FENGGE.getName());
		fengGeStar.setGongZhi(fengGeDiZhi);
		starMap.put(StarCode.FENGGE, fengGeStar);
		gongList.get(fengGeDiZhi.ordinal()).getZaYaoList().add(fengGeStar);

		//安天哭
		DiZhi tianKuDiZhi = ZhiXiZhuXingBiao.anTianKu(basicInfo.getDiZhi());
		Star tianKuiStar = new Star(StarCode.TIANKU, StarCode.TIANKU.getName());
		tianKuiStar.setGongZhi(tianKuDiZhi);
		starMap.put(StarCode.TIANKU, tianKuiStar);
		gongList.get(tianKuDiZhi.ordinal()).getZaYaoList().add(tianKuiStar);

		//安天虚
		DiZhi tianXuDiZhi = ZhiXiZhuXingBiao.anTianXu(basicInfo.getDiZhi());
		Star tianXuStar = new Star(StarCode.TIANXU, StarCode.TIANXU.getName());
		tianXuStar.setGongZhi(tianXuDiZhi);
		starMap.put(StarCode.TIANXU, tianXuStar);
		gongList.get(tianXuDiZhi.ordinal()).getZaYaoList().add(tianXuStar);
		
		//安孤辰
		DiZhi guChenDiZhi = ZhiXiZhuXingBiao.anGuChen(basicInfo.getDiZhi());
		Star guChenStar = new Star(StarCode.GUCHEN, StarCode.GUCHEN.getName());
		guChenStar.setGongZhi(guChenDiZhi);
		starMap.put(StarCode.GUCHEN, guChenStar);
		gongList.get(guChenDiZhi.ordinal()).getZaYaoList().add(guChenStar);

		//安寡宿
		DiZhi guaSuDiZhi = ZhiXiZhuXingBiao.anGuaSu(basicInfo.getDiZhi());
		Star guaSuStar = new Star(StarCode.GUASU, StarCode.GUASU.getName());
		guaSuStar.setGongZhi(guaSuDiZhi);
		starMap.put(StarCode.GUASU, guaSuStar);
		gongList.get(guaSuDiZhi.ordinal()).getZaYaoList().add(guaSuStar);
		
		//安华盖
		DiZhi huaGaiDiZhi = ZhiXiZhuXingBiao.anHuaGai(basicInfo.getDiZhi());
		Star huaGaiStar = new Star(StarCode.HUAGAI, StarCode.HUAGAI.getName());
		huaGaiStar.setGongZhi(huaGaiDiZhi);
		starMap.put(StarCode.HUAGAI, huaGaiStar);
		gongList.get(huaGaiDiZhi.ordinal()).getZaYaoList().add(huaGaiStar);
		
		//安劫煞
		DiZhi jieShaDiZhi = ZhiXiZhuXingBiao.anJieSha(basicInfo.getDiZhi());
		Star jieShaStar = new Star(StarCode.JIESHA, StarCode.JIESHA.getName());
		jieShaStar.setGongZhi(jieShaDiZhi);
		starMap.put(StarCode.JIESHA, jieShaStar);
		gongList.get(jieShaDiZhi.ordinal()).getZaYaoList().add(jieShaStar);
		
		//安咸池
		DiZhi xianChiDiZhi = ZhiXiZhuXingBiao.anXianChi(basicInfo.getDiZhi());
		Star xianChiStar = new Star(StarCode.XIANCHI, StarCode.XIANCHI.getName());
		xianChiStar.setGongZhi(xianChiDiZhi);
		starMap.put(StarCode.XIANCHI, xianChiStar);
		gongList.get(xianChiDiZhi.ordinal()).getZaYaoList().add(xianChiStar);
		
		//安火星
		DiZhi huoXingDiZhi = ZhiXiZhuXingBiao.anHuoXing(basicInfo.getDiZhi(), basicInfo.getShiChen());
		Star huoXingStar = new Star(StarCode.HUOXING, StarCode.HUOXING.getName());
		huoXingStar.setGongZhi(huoXingDiZhi);
		starMap.put(StarCode.HUOXING, huoXingStar);
		gongList.get(huoXingDiZhi.ordinal()).getFuYaoList().add(huoXingStar);

		//安铃星
		DiZhi lingXingDiZhi = ZhiXiZhuXingBiao.anLingXing(basicInfo.getDiZhi(), basicInfo.getShiChen());
		Star lingXingStar = new Star(StarCode.LINGXING, StarCode.LINGXING.getName());
		lingXingStar.setGongZhi(lingXingDiZhi);
		starMap.put(StarCode.LINGXING, lingXingStar);
		gongList.get(lingXingDiZhi.ordinal()).getFuYaoList().add(lingXingStar);
		
		//安天马
		DiZhi tianMaDiZhi = ZhiXiZhuXingBiao.anTianMa(basicInfo.getDiZhi());
		Star tianMaStar = new Star(StarCode.TIANMA, StarCode.TIANMA.getName());
		tianMaStar.setGongZhi(tianMaDiZhi);
		starMap.put(StarCode.TIANMA, tianMaStar);
		gongList.get(tianMaDiZhi.ordinal()).getFuYaoList().add(tianMaStar);

		//安大耗
		DiZhi daHaoDiZhi = ZhiXiZhuXingBiao.anDaHao(basicInfo.getDiZhi());
		Star daHaoStar = new Star(StarCode.DAHAO, StarCode.DAHAO.getName()); 
		daHaoStar.setGongZhi(daHaoDiZhi);
		starMap.put(StarCode.DAHAO, daHaoStar);
		gongList.get(daHaoDiZhi.ordinal()).getZaYaoList().add(daHaoStar);

		//安破碎
		DiZhi poSuiDiZhi = ZhiXiZhuXingBiao.anPoSui(basicInfo.getDiZhi());
		Star poSuiStar = new Star(StarCode.POSUI, StarCode.POSUI.getName());
		poSuiStar.setGongZhi(poSuiDiZhi);
		starMap.put(StarCode.POSUI, poSuiStar);
		gongList.get(poSuiDiZhi.ordinal()).getZaYaoList().add(poSuiStar);
		
		//安天空
		DiZhi tianKongDiZhi = ZhiXiZhuXingBiao.anTianKong(basicInfo.getDiZhi());
		Star tianKongStar = new Star(StarCode.TIANKONG, StarCode.TIANKONG.getName());
		tianKongStar.setGongZhi(tianKongDiZhi);
		starMap.put(StarCode.TIANKONG, tianKongStar);
		gongList.get(tianKongDiZhi.ordinal()).getZaYaoList().add(tianKongStar);

		//安天德
		DiZhi tianDeDiZhi = ZhiXiZhuXingBiao.anTianDe(basicInfo.getDiZhi());
		Star tianDeStar = new Star(StarCode.TIANDE, StarCode.TIANDE.getName());
		tianDeStar.setGongZhi(tianDeDiZhi);
		starMap.put(StarCode.TIANDE, tianDeStar);
		gongList.get(tianDeDiZhi.ordinal()).getZaYaoList().add(tianDeStar);
		
		//安年解
		DiZhi nianJieDiZhi = ZhiXiZhuXingBiao.anNianJie(basicInfo.getDiZhi());
		Star nianJieStar = new Star(StarCode.NIANJIE, StarCode.NIANJIE.getName());
		nianJieStar.setGongZhi(nianJieDiZhi);
		starMap.put(StarCode.NIANJIE, nianJieStar);
		gongList.get(nianJieDiZhi.ordinal()).getZaYaoList().add(nianJieStar);
		
		//安旬空
		DiZhi xunKong1DiZhi = ZhiXiZhuXingBiao.anXunKong1(basicInfo.getYear());
		DiZhi xunKong2DiZhi = ZhiXiZhuXingBiao.anXunKong2(basicInfo.getYear());
		
		Star zhengXunKong = new Star(StarCode.ZHENGXUNKONG, StarCode.ZHENGXUNKONG.getName()); 
		Star bangXunKong = new Star(StarCode.BANGXUNKONG, StarCode.BANGXUNKONG.getName());
	
		if(basicInfo.getTianGan().ordinal() % 2 == 0){
			//天干为阳
			zhengXunKong.setGongZhi(xunKong1DiZhi);
			bangXunKong.setGongZhi(xunKong2DiZhi);
		}else{
			zhengXunKong.setGongZhi(xunKong2DiZhi);
			bangXunKong.setGongZhi(xunKong1DiZhi);
		}
		
		starMap.put(StarCode.ZHENGXUNKONG, zhengXunKong);
		gongList.get(xunKong1DiZhi.ordinal()).getZaYaoList().add(zhengXunKong);
		starMap.put(StarCode.BANGXUNKONG, bangXunKong);
		gongList.get(xunKong2DiZhi.ordinal()).getZaYaoList().add(bangXunKong);

		//安月德
		DiZhi yueDeDiZhi = ZhiXiZhuXingBiao.anYueDe(basicInfo.getDiZhi());
		Star yueDeStar = new Star(StarCode.YUEDE, StarCode.YUEDE.getName()); 
		yueDeStar.setGongZhi(yueDeDiZhi);
		starMap.put(StarCode.YUEDE, yueDeStar);
		gongList.get(yueDeDiZhi.ordinal()).getZaYaoList().add(yueDeStar);
		
		//安蜚廉
		DiZhi feiLianDiZhi = ZhiXiZhuXingBiao.anFeiLian(basicInfo.getDiZhi());
		Star feiLianStar = new Star(StarCode.FEILIAN, StarCode.FEILIAN.getName());
		feiLianStar.setGongZhi(feiLianDiZhi);
		starMap.put(StarCode.FEILIAN, feiLianStar);
		gongList.get(feiLianDiZhi.ordinal()).getZaYaoList().add(feiLianStar);

	}
	
	private void anYueXiZhuXing(){
		//安左辅
		DiZhi zuoFuDiZhi = YueXiZhuXingBiao.anZuoFu(basicInfo.getMonth());
		Star zuoFuStar = new Star(StarCode.ZUOFU, StarCode.ZUOFU.getName());
		zuoFuStar.setGongZhi(zuoFuDiZhi);
		starMap.put(StarCode.ZUOFU, zuoFuStar);
		gongList.get(zuoFuDiZhi.ordinal()).getFuYaoList().add(zuoFuStar);

		//安右弼
		DiZhi youBiDiZhi = YueXiZhuXingBiao.anYouBi(basicInfo.getMonth());
		Star youBiStar = new Star(StarCode.YOUBI, StarCode.YOUBI.getName());
		youBiStar.setGongZhi(youBiDiZhi);
		starMap.put(StarCode.YOUBI, youBiStar);
		gongList.get(youBiDiZhi.ordinal()).getFuYaoList().add(youBiStar);
		
		//安天刑
		DiZhi tianXingDiZhi = YueXiZhuXingBiao.anTianXing(basicInfo.getMonth());
		Star tianXingStar = new Star(StarCode.TIANXING, StarCode.TIANXING.getName());
		tianXingStar.setGongZhi(tianXingDiZhi);
		starMap.put(StarCode.TIANXING, tianXingStar);
		gongList.get(tianXingDiZhi.ordinal()).getZaYaoList().add(tianXingStar);

		//安天姚
		DiZhi tianYaoDiZhi = YueXiZhuXingBiao.anTianYao(basicInfo.getMonth());
		Star tianYaoStar = new Star(StarCode.TIANYAO, StarCode.TIANYAO.getName());
		tianYaoStar.setGongZhi(tianYaoDiZhi);
		starMap.put(StarCode.TIANYAO, tianYaoStar);
		gongList.get(tianYaoDiZhi.ordinal()).getZaYaoList().add(tianYaoStar);

		//安天巫
		DiZhi tianWuDiZhi = YueXiZhuXingBiao.anTianWu(basicInfo.getMonth());
		Star tianWuStar = new Star(StarCode.TIANWU, StarCode.TIANWU.getName());
		tianWuStar.setGongZhi(tianWuDiZhi);
		starMap.put(StarCode.TIANWU, tianWuStar);
		gongList.get(tianWuDiZhi.ordinal()).getZaYaoList().add(tianWuStar);

		//安解神
		DiZhi jieShenDiZhi = YueXiZhuXingBiao.anJieShen(basicInfo.getMonth());
		Star jieShenStar = new Star(StarCode.JIESHEN, StarCode.JIESHEN.getName());
		jieShenStar.setGongZhi(jieShenDiZhi);
		starMap.put(StarCode.JIESHEN, jieShenStar);
		gongList.get(jieShenDiZhi.ordinal()).getZaYaoList().add(jieShenStar);
		
		//安阴煞
		DiZhi yinShaDiZhi = YueXiZhuXingBiao.anYinSha(basicInfo.getMonth());
		Star yinShaStar = new Star(StarCode.YINSHA, StarCode.YINSHA.getName());
		yinShaStar.setGongZhi(yinShaDiZhi);
		starMap.put(StarCode.YINSHA, yinShaStar);
		gongList.get(yinShaDiZhi.ordinal()).getZaYaoList().add(yinShaStar);
		
		//安天月
		DiZhi tianYueDiZhi = YueXiZhuXingBiao.getTianYue1ByMonth(basicInfo.getMonth());
		Star tianYueStar = new Star(StarCode.TIANYUE1, StarCode.TIANYUE1.getName());
		tianYueStar.setGongZhi(tianYueDiZhi);
		starMap.put(StarCode.TIANYUE1, tianYueStar);
		gongList.get(tianYueDiZhi.ordinal()).getZaYaoList().add(tianYueStar);

	}
	
	private void anRiXiZhuXing(){
		//安三台
		DiZhi sanTaiDiZhi = RiXiZhuXingBiao.anSanTai(basicInfo.getMonth(), basicInfo.getDay());
		Star sanTaiStar = new Star(StarCode.SANTAI, StarCode.SANTAI.getName());
		sanTaiStar.setGongZhi(sanTaiDiZhi);
		starMap.put(StarCode.SANTAI, sanTaiStar);
		gongList.get(sanTaiDiZhi.ordinal()).getZaYaoList().add(sanTaiStar);

		//安八座
		DiZhi baZuoDiZhi = RiXiZhuXingBiao.anBaZuo(basicInfo.getMonth(), basicInfo.getDay());
		Star baZuoStar = new Star(StarCode.BAZUO, StarCode.BAZUO.getName());
		baZuoStar.setGongZhi(baZuoDiZhi);
		starMap.put(StarCode.BAZUO, baZuoStar);
		gongList.get(baZuoDiZhi.ordinal()).getZaYaoList().add(baZuoStar);

		//安恩光
		DiZhi enGuangDiZhi = RiXiZhuXingBiao.anEnGuang(basicInfo.getShiChen(), basicInfo.getDay());
		Star enGuangStar = new Star(StarCode.ENGUANG, StarCode.ENGUANG.getName());
		enGuangStar.setGongZhi(enGuangDiZhi);
		starMap.put(StarCode.ENGUANG, enGuangStar);
		gongList.get(enGuangDiZhi.ordinal()).getZaYaoList().add(enGuangStar);

		//安天贵
		DiZhi tianGuiDiZhi = RiXiZhuXingBiao.anTianGui(basicInfo.getShiChen(), basicInfo.getDay());
		Star tianGuiStar = new Star(StarCode.TIANGUI, StarCode.TIANGUI.getName()); 
		tianGuiStar.setGongZhi(tianGuiDiZhi);
		starMap.put(StarCode.TIANGUI, tianGuiStar);
		gongList.get(tianGuiDiZhi.ordinal()).getZaYaoList().add(tianGuiStar);
		
	}
	
	private void anShiXiZhuXing(){
		//安文昌
		DiZhi wenChangDiZhi = ShiXiZhuXingBiao.anWenChang(basicInfo.getShiChen());
		Star wenChangStar = new Star(StarCode.WENCHANG, StarCode.WENCHANG.getName());
		wenChangStar.setGongZhi(wenChangDiZhi);
		starMap.put(StarCode.WENCHANG, wenChangStar);
		gongList.get(wenChangDiZhi.ordinal()).getFuYaoList().add(wenChangStar);

		//安文曲
		DiZhi wenQuDiZhi = ShiXiZhuXingBiao.anWenQu(basicInfo.getShiChen());
		Star wenQuStar = new Star(StarCode.WENQU, StarCode.WENQU.getName());
		wenQuStar.setGongZhi(wenQuDiZhi);
		starMap.put(StarCode.WENQU, wenQuStar);
		gongList.get(wenQuDiZhi.ordinal()).getFuYaoList().add(wenQuStar);

		//安地劫
		DiZhi diJieDiZhi = ShiXiZhuXingBiao.anDiJie(basicInfo.getShiChen());
		Star diJieStar = new Star(StarCode.DIJIE, StarCode.DIJIE.getName());
		diJieStar.setGongZhi(diJieDiZhi);
		starMap.put(StarCode.DIJIE, diJieStar);
		gongList.get(diJieDiZhi.ordinal()).getZaYaoList().add(diJieStar);

		//安地空
		DiZhi diKongDiZhi = ShiXiZhuXingBiao.anDiKong(basicInfo.getShiChen());
		Star diKongStar = new Star(StarCode.DIKONG, StarCode.DIKONG.getName());
		diKongStar.setGongZhi(diKongDiZhi);
		starMap.put(StarCode.DIKONG, diKongStar);
		gongList.get(diKongDiZhi.ordinal()).getZaYaoList().add(diKongStar);
		
		//安台辅
		DiZhi taiFuDiZhi = ShiXiZhuXingBiao.anTaiFu(basicInfo.getShiChen());
		Star taiFuStar = new Star(StarCode.TAIFU, StarCode.TAIFU.getName());
		taiFuStar.setGongZhi(taiFuDiZhi);
		starMap.put(StarCode.TAIFU, taiFuStar);
		gongList.get(taiFuDiZhi.ordinal()).getZaYaoList().add(taiFuStar);
	
		//安封诰
		DiZhi fengGaoDiZhi = ShiXiZhuXingBiao.anFengGao(basicInfo.getShiChen());
		Star fengGaoStar = new Star(StarCode.FENGGAO, StarCode.FENGGAO.getName());
		fengGaoStar.setGongZhi(fengGaoDiZhi);
		starMap.put(StarCode.FENGGAO, fengGaoStar);
		gongList.get(fengGaoDiZhi.ordinal()).getZaYaoList().add(fengGaoStar);

	}
	
	private void anZaXing(){
		//安天伤
		DiZhi tianShangDiZhi = ZaXingBiao.anTianShang(basicInfo.getShiChen(), basicInfo.getMonth(), basicInfo.getYinYang(), basicInfo.getSex());
		Star tianShangStar = new Star(StarCode.TIANSHANG, StarCode.TIANSHANG.getName());
		tianShangStar.setGongZhi(tianShangDiZhi);
		starMap.put(StarCode.TIANSHANG, tianShangStar);
		gongList.get(tianShangDiZhi.ordinal()).getZaYaoList().add(tianShangStar);

		//安天使
		DiZhi tianShiDiZhi = ZaXingBiao.anTianShi(basicInfo.getShiChen(), basicInfo.getMonth(), basicInfo.getYinYang(), basicInfo.getSex());
		Star tianShiStar = new Star(StarCode.TIANSHI, StarCode.TIANSHI.getName());
		tianShiStar.setGongZhi(tianShiDiZhi);
		starMap.put(StarCode.TIANSHI, tianShiStar);
		gongList.get(tianShiDiZhi.ordinal()).getZaYaoList().add(tianShiStar);
		
		//安天才
		DiZhi tianCaiDiZhi = ZaXingBiao.anTianCai(basicInfo.getShiChen(), basicInfo.getMonth(), basicInfo.getDiZhi());
		Star tianCaiStar = new Star(StarCode.TIANCAI, StarCode.TIANCAI.getName()); 
		tianCaiStar.setGongZhi(tianCaiDiZhi);
		starMap.put(StarCode.TIANCAI, tianCaiStar);
		gongList.get(tianCaiDiZhi.ordinal()).getZaYaoList().add(tianCaiStar);
		
		//安天寿
		DiZhi tianShouDiZhi = ZaXingBiao.anTianShou(basicInfo.getShiChen(), basicInfo.getMonth(), basicInfo.getDiZhi());
		Star tianShouStar = new Star(StarCode.TIANSHOU, StarCode.TIANSHOU.getName());
		tianShouStar.setGongZhi(tianShouDiZhi);
		starMap.put(StarCode.TIANSHOU, tianShouStar);
		gongList.get(tianShouDiZhi.ordinal()).getZaYaoList().add(tianShouStar);
	}
	
	private void anSiHuaXing(){
		//安化禄
		StarCode huaLuStarCode = GanXiZhuXingBiao.anHuaLu(basicInfo.getTianGan());
		Star huaLuStar = starMap.get(huaLuStarCode);
		huaLuStar.setSiHua(StarCode.HUALU);
		
		//安化权
		StarCode huaQuanStarCode = GanXiZhuXingBiao.anHuaQuan(basicInfo.getTianGan());
		Star huaQuanStar = starMap.get(huaQuanStarCode);
		huaQuanStar.setSiHua(StarCode.HUAQUAN);
		
		//安化科
		StarCode huaKeStarCode = GanXiZhuXingBiao.anHuaKe(basicInfo.getTianGan());
		Star huaKeStar = starMap.get(huaKeStarCode);
		huaKeStar.setSiHua(StarCode.HUAKE);
		
		//安化忌
		StarCode huaJiStarCode = GanXiZhuXingBiao.anHuaJi(basicInfo.getTianGan());
		Star huaJiStar = starMap.get(huaJiStarCode);
		huaJiStar.setSiHua(StarCode.HUAJI);
	}
	
	private void dingMiaoXian(){
		Iterator<?> iter = starMap.entrySet().iterator();
		while(iter.hasNext()){
			@SuppressWarnings("rawtypes")
			Map.Entry entry = (Map.Entry) iter.next();
			StarCode key = (StarCode) entry.getKey();
			Star star = (Star) entry.getValue();
			MiaoXian mx = MiaoXianBiao.dingMiaoXian(key, star.getGongZhi());
			star.setStarMX(mx);
		}
	}
	
	/**
	 * 天盘十二宫指示人一生祸福，大限十二宫指示某十年祸福
	 */
	private void dingDaXian(){

		for(int i=0; i < gongList.size(); i++){
			
			int index = 0;
			//阳男阴女顺行；阴男阳女逆行
			if((basicInfo.getSex() == Sex.F && basicInfo.getYinYang() == YinYang.YIN) || (basicInfo.getSex() == Sex.M && basicInfo.getYinYang() == YinYang.YANG)){
				index = (mingGong.ordinal() + i) %12;
			}else if((basicInfo.getSex() == Sex.F && basicInfo.getYinYang() == YinYang.YANG) || (basicInfo.getSex() == Sex.M && basicInfo.getYinYang() == YinYang.YIN)){
				index = (mingGong.ordinal() + 12 - i) % 12;
			}
			
			Gong gong = gongList.get(index);
			gong.setStartDaXian(basicInfo.getWuXing().getNum() + i*10);
			gong.setEndDaXian(basicInfo.getWuXing().getNum()+(i+1)*10 -1);
			
			/**
			 * 计算当前年所在大限
			 */
			int age = basicInfo.getAge();
			if(gong.getStartDaXian() <= age && gong.getEndDaXian() >= age){
				basicInfo.setDaXian(gong.getGongZhi());
			}
		}
		
		/**
		 * 小儿童限
		 * 一岁命宫，二岁财帛，三岁疾厄，四岁夫妻，五岁福德，六岁事业
		 * 童限时只看本宫的三方四正，不逆布十二宫，即只看命宫，无法兼视六亲及周围环境
		 */
		switch(basicInfo.getAge()){
		case 1:
			basicInfo.setDaXian(mingGong);
			break;
		case 2:
			basicInfo.setDaXian(DiZhi.values()[(mingGong.ordinal()+4)%12]);
			break;
		case 3:
			basicInfo.setDaXian(DiZhi.values()[(mingGong.ordinal()+5)%12]);
			break;
		case 4:
			basicInfo.setDaXian(DiZhi.values()[(mingGong.ordinal()+2)%12]);
			break;
		case 5:
			basicInfo.setDaXian(DiZhi.values()[(mingGong.ordinal()+10)%12]);
			break;
		case 6:
			basicInfo.setDaXian(DiZhi.values()[(mingGong.ordinal()+8)%12]);
			break;
		default:
			break;
		}

		if(basicInfo.getDaXian() == null){
			basicInfo.setDaXian(mingGong);
		}
		/**
		 * 计算当前年大限所在的宫为命宫，重新排列十二宫，得到大限十二宫
		 * 推算十年大限时，以天盘中的星曜凶吉作为体，大限中的星曜凶吉作为用
		 * 观察大限各宫的星曜吉凶庙陷，同时根据三方四正，决定十年祸福
		 */
		for(Gong gong: gongList){
			gong.setDaYunShiErGong(ShiErGong.values()[(12 + basicInfo.getDaXian().ordinal() - gong.getGongZhi().ordinal())%12]);
		}
	}
	
	/**
	 * 用大限命宫的干支来寻找流曜
	 * 中州派用于大限、流年、月、曰、时的星曜有：
	 * 流魁、流钺、流禄、流羊、流陀、流昌、流曲、化流禄、化流权、化流科、化流忌。其中流[魁钺羊陀禄存]、流[四化]的起法与起星盘的方法相同。流[昌曲]不同
	 * 例如癸丑年五月十七日巳时阴男，第二个大运在子宫，以子宫为命宫，宫干为甲
	 * 就要按甲干、子支寻找流曜，如流禄在寅，流化禄为廉贞。。。
	 * 流年、流月、流日、流时计算相同
	 */
	private void anDaYunZhuXing(){
		TianGan tianGan = gongList.get(basicInfo.getDaXian().ordinal()).getGongGan();
		//安运魁
		DiZhi yunKuiDiZhi = GanXiZhuXingBiao.anTianKui(tianGan);
		Star yunKuiStar = new Star(StarCode.YUNKUI, StarCode.YUNKUI.getName());
		yunKuiStar.setGongZhi(yunKuiDiZhi);
		starMap.put(StarCode.YUNKUI, yunKuiStar);
		gongList.get(yunKuiDiZhi.ordinal()).getYunYaoList().add(yunKuiStar);

		//安运钺
		DiZhi yunYueDiZhi = GanXiZhuXingBiao.anTianYue(tianGan);
		Star yunYueStar = new Star(StarCode.YUNYUE, StarCode.YUNYUE.getName());
		yunYueStar.setGongZhi(yunYueDiZhi);
		starMap.put(StarCode.YUNYUE, yunYueStar);
		gongList.get(yunYueDiZhi.ordinal()).getYunYaoList().add(yunYueStar);
		
		//安运羊
		DiZhi yunYangDiZhi = GanXiZhuXingBiao.anQingYang(tianGan);
		Star yunYangStar = new Star(StarCode.YUNYANG, StarCode.YUNYANG.getName());
		yunYangStar.setGongZhi(yunYangDiZhi);
		starMap.put(StarCode.YUNYANG, yunYangStar);
		gongList.get(yunYangDiZhi.ordinal()).getYunYaoList().add(yunYangStar);
		
		//安运驼
		DiZhi yunTuoDiZhi = GanXiZhuXingBiao.anTuoLuo(tianGan);
		Star yunTuoStar = new Star(StarCode.YUNTUO, StarCode.YUNTUO.getName());
		yunTuoStar.setGongZhi(yunTuoDiZhi);
		starMap.put(StarCode.YUNTUO, yunTuoStar);
		gongList.get(yunTuoDiZhi.ordinal()).getYunYaoList().add(yunTuoStar);
		
		//安运禄
		DiZhi yunLuDiZhi = GanXiZhuXingBiao.anLuCun(tianGan);
		Star yunLuStar = new Star(StarCode.YUNLU, StarCode.YUNLU.getName());
		yunLuStar.setGongZhi(yunLuDiZhi);
		starMap.put(StarCode.YUNLU, yunLuStar);
		gongList.get(yunLuDiZhi.ordinal()).getYunYaoList().add(yunLuStar);
		
		//安运昌
		DiZhi yunChangDiZhi = Utils.anLiuChang(tianGan);
		Star yunChangStar = new Star(StarCode.YUNCHANG, StarCode.YUNCHANG.getName());
		yunChangStar.setGongZhi(yunChangDiZhi);
		starMap.put(StarCode.YUNCHANG, yunChangStar);
		gongList.get(yunChangDiZhi.ordinal()).getYunYaoList().add(yunChangStar);

		//安运曲
		DiZhi yunQuDiZhi = Utils.anLiuQu(tianGan);
		Star yunQuStar = new Star(StarCode.YUNQU, StarCode.YUNQU.getName());
		yunQuStar.setGongZhi(yunQuDiZhi);
		starMap.put(StarCode.YUNQU, yunQuStar);
		gongList.get(yunQuDiZhi.ordinal()).getYunYaoList().add(yunQuStar);
		
		//安运化禄
		StarCode huaLuStarCode = GanXiZhuXingBiao.anHuaLu(tianGan);
		Star huaLuStar = starMap.get(huaLuStarCode);
		huaLuStar.setDaYunSiHua(StarCode.HUALU);
		
		//安运化权
		StarCode huaQuanStarCode = GanXiZhuXingBiao.anHuaQuan(tianGan);
		Star huaQuanStar = starMap.get(huaQuanStarCode);
		huaQuanStar.setDaYunSiHua(StarCode.HUAQUAN);
		
		//安运化科
		StarCode huaKeStarCode = GanXiZhuXingBiao.anHuaKe(tianGan);
		Star huaKeStar = starMap.get(huaKeStarCode);
		huaKeStar.setDaYunSiHua(StarCode.HUAKE);
		
		//安运化忌
		StarCode huaJiStarCode = GanXiZhuXingBiao.anHuaJi(tianGan);
		Star huaJiStar = starMap.get(huaJiStarCode);
		huaJiStar.setDaYunSiHua(StarCode.HUAJI);
	}
	
	/**
	 * 大限定十年祸福，小限主一年吉凶
	 * 流年太岁的地支为命宫，例如壬辰年，则太岁在辰，起命宫，将十二宫逆排
	 * 以壬天干起流曜
	 */
	private void anLiuNianZhuXing(){
		for(Gong gong: gongList){
			gong.setLiuNianShiErGong(ShiErGong.values()[(12 + Utils.convertToDiZhi(this.curYear).ordinal() - gong.getGongZhi().ordinal())%12]);
		}	
		
		TianGan tianGan = Utils.convertToTianGan(this.curYear);
		DiZhi diZhi = Utils.convertToDiZhi(this.curYear);
		
		//安流魁
		DiZhi liuKuiDiZhi = GanXiZhuXingBiao.anTianKui(tianGan);
		Star liuKuiStar = new Star(StarCode.LIUKUI, StarCode.LIUKUI.getName());
		liuKuiStar.setGongZhi(liuKuiDiZhi);
		starMap.put(StarCode.LIUKUI, liuKuiStar);
		gongList.get(liuKuiDiZhi.ordinal()).getLiuYaoList().add(liuKuiStar);

		//安流钺
		DiZhi liuYueDiZhi = GanXiZhuXingBiao.anTianYue(tianGan);
		Star liuYueStar = new Star(StarCode.LIUYUE, StarCode.LIUYUE.getName());
		liuYueStar.setGongZhi(liuYueDiZhi);
		starMap.put(StarCode.LIUYUE, liuYueStar);
		gongList.get(liuYueDiZhi.ordinal()).getLiuYaoList().add(liuYueStar);
		
		//安流羊
		DiZhi liuYangDiZhi = GanXiZhuXingBiao.anQingYang(tianGan);
		Star liuYangStar = new Star(StarCode.LIUYANG, StarCode.LIUYANG.getName());
		liuYangStar.setGongZhi(liuYangDiZhi);
		starMap.put(StarCode.LIUYANG, liuYangStar);
		gongList.get(liuYangDiZhi.ordinal()).getLiuYaoList().add(liuYangStar);
		
		//安流驼
		DiZhi liuTuoDiZhi = GanXiZhuXingBiao.anTuoLuo(tianGan);
		Star liuTuoStar = new Star(StarCode.LIUTUO, StarCode.LIUTUO.getName());
		liuTuoStar.setGongZhi(liuTuoDiZhi);
		starMap.put(StarCode.LIUTUO, liuTuoStar);
		gongList.get(liuTuoDiZhi.ordinal()).getLiuYaoList().add(liuTuoStar);
		
		//安流禄
		DiZhi liuLuDiZhi = GanXiZhuXingBiao.anLuCun(tianGan);
		Star liuLuStar = new Star(StarCode.LIULU, StarCode.LIULU.getName());
		liuLuStar.setGongZhi(liuLuDiZhi);
		starMap.put(StarCode.LIULU, liuLuStar);
		gongList.get(liuLuDiZhi.ordinal()).getLiuYaoList().add(liuLuStar);
		
		//安流昌
		DiZhi liuChangDiZhi = Utils.anLiuChang(tianGan);
		Star liuChangStar = new Star(StarCode.LIUCHANG, StarCode.LIUCHANG.getName());
		liuChangStar.setGongZhi(liuChangDiZhi);
		starMap.put(StarCode.LIUCHANG, liuChangStar);
		gongList.get(liuChangDiZhi.ordinal()).getLiuYaoList().add(liuChangStar);

		//安流曲
		DiZhi liuQuDiZhi = Utils.anLiuQu(tianGan);
		Star liuQuStar = new Star(StarCode.LIUQU, StarCode.LIUQU.getName());
		liuQuStar.setGongZhi(liuQuDiZhi);
		starMap.put(StarCode.LIUQU, liuQuStar);
		gongList.get(liuQuDiZhi.ordinal()).getLiuYaoList().add(liuQuStar);
		
		//安流马
		DiZhi liuMaDiZhi = ZhiXiZhuXingBiao.anTianMa(diZhi);
		Star liuMaStar = new Star(StarCode.LIUMA, StarCode.LIUMA.getName());
		liuMaStar.setGongZhi(liuMaDiZhi);
		starMap.put(StarCode.LIUMA, liuMaStar);
		gongList.get(liuMaDiZhi.ordinal()).getLiuYaoList().add(liuMaStar);
		
		//安流鸾
		DiZhi liuLuanDiZhi = ZhiXiZhuXingBiao.anHongLuan(diZhi);
		Star liuLuanStar = new Star(StarCode.LIULUAN, StarCode.LIULUAN.getName());
		liuLuanStar.setGongZhi(liuLuanDiZhi);
		starMap.put(StarCode.LIULUAN, liuLuanStar);
		gongList.get(liuLuanDiZhi.ordinal()).getLiuYaoList().add(liuLuanStar);
		
		//安流喜
		DiZhi liuXiDiZhi = ZhiXiZhuXingBiao.anTianXi(diZhi);
		Star liuXiStar = new Star(StarCode.LIUXI, StarCode.LIUXI.getName());
		liuXiStar.setGongZhi(liuXiDiZhi);
		starMap.put(StarCode.LIUXI, liuXiStar);
		gongList.get(liuXiDiZhi.ordinal()).getLiuYaoList().add(liuXiStar);
		
		//安流化禄
		StarCode huaLuStarCode = GanXiZhuXingBiao.anHuaLu(tianGan);
		Star huaLuStar = starMap.get(huaLuStarCode);
		huaLuStar.setLiuNianSiHua(StarCode.HUALU);
		
		//安流化权
		StarCode huaQuanStarCode = GanXiZhuXingBiao.anHuaQuan(tianGan);
		Star huaQuanStar = starMap.get(huaQuanStarCode);
		huaQuanStar.setLiuNianSiHua(StarCode.HUAQUAN);
		
		//安流化科
		StarCode huaKeStarCode = GanXiZhuXingBiao.anHuaKe(tianGan);
		Star huaKeStar = starMap.get(huaKeStarCode);
		huaKeStar.setLiuNianSiHua(StarCode.HUAKE);
		
		//安流化忌
		StarCode huaJiStarCode = GanXiZhuXingBiao.anHuaJi(tianGan);
		Star huaJiStar = starMap.get(huaJiStarCode);
		huaJiStar.setLiuNianSiHua(StarCode.HUAJI);
	}
	
	/**
	 * 流月主每个月吉凶
	 */
	private void anLiuYueZhuXing(){
		/**
		 * 安斗君
		 * 以流年太岁（即流年地支）所在宫起正月，逆数到出生月宫上，再以该宫起子时，顺数到出生时辰止，即在此宫安斗君。生年斗君定出后，以后逐年斗君可顺盘而推，一年一宫。
		 * 例如：2012年为壬辰年，农历3月卯时生人，以辰宫起正月，逆时针数卯宫为二月，寅宫为三月，于寅宫起子时，顺时针数卯宫为丑时，辰宫为寅时，巳宫为卯时，巳宫为此人2012年的斗君
		 */
		DiZhi taiSui = Utils.convertToDiZhi(this.curYear);
		int gongZhi = (taiSui.ordinal()-basicInfo.getMonth() + 12) % 12;
		Gong douJun = gongList.get((gongZhi + basicInfo.getShiChen().ordinal() - 1)%12);
		
		/**
		 * 根据斗君所在的宫起正月，顺时针数十二个流月
		 * 断每个月的吉凶，则是依据流月中的星曜，及其三方四正的星曜是吉是凶 
		 */
		for(int i=0; i<gongList.size(); i++){
			Gong gong = gongList.get(i);
			gong.setLiuYue((12 - douJun.getGongZhi().ordinal() + i)%12);
			if(gong.getLiuYue() == 0){
				gong.setLiuYue(12);
			}
		}
	}
	
	public BasicInfo getBasicInfo() {
		return basicInfo;
	}

	public void setBasicInfo(BasicInfo basicInfo) {
		this.basicInfo = basicInfo;
	}

	public List<Gong> getGongList() {
		return gongList;
	}

	public void setGongList(List<Gong> gongList) {
		this.gongList = gongList;
	}

	public DiZhi getMingGong() {
		return mingGong;
	}

	public void setMingGong(DiZhi mingGong) {
		this.mingGong = mingGong;
	}
	
	public DiZhi getShenGong() {
		return shenGong;
	}

	public void setShenGong(DiZhi shenGong) {
		this.shenGong = shenGong;
	}
}
